﻿using System.IO;

namespace AI3SaveEditor.AI3Files
{
    public class Js3fmiFile : ClothesFile
    {
        Js3fsiFile js3fsiFile;
        public const int NameLength = 64;


        public Js3fmiFile(string fileName)
            : base(fileName) {
            this.js3fsiFile = new Js3fsiFile(PathHelper.Combine(Path.GetDirectoryName(file.FullName),
                Path.GetFileNameWithoutExtension(file.FullName), Path.GetFileNameWithoutExtension(file.FullName) + ".js3fsi"));
            Load();
        }

        public override void Save() {
            base.Save();
            js3fsiFile.Save();
        }

        public override string Name {
            get {
                return base.Name;
            }
            set {
                base.Name = value;
                js3fsiFile.Name = value;
            }
        }

        public override void ChangeFileName() {
            string sourceFile = this.FileName;
            if (File.Exists(sourceFile))
                File.Move(sourceFile, Path.Combine(Path.GetDirectoryName(sourceFile), this.Name + ".js3fmi"));

            sourceFile = Path.Combine(Path.GetDirectoryName(this.FileName), Path.GetFileNameWithoutExtension(this.FileName) + "_v.bmp");
            if (File.Exists(sourceFile))
                File.Move(sourceFile, Path.Combine(Path.GetDirectoryName(sourceFile), this.Name + "_v.bmp"));

            js3fsiFile.ChangeFileName();
        }
    }
}
